local zhenyuan = fk.CreateSkill {
  name = "lvshi__zhenyuan",
  anim_type = "control",
  tags = {"ready_skill"},
}


Fk:loadTranslationTable{
  ["lvshi__zhenyuan"] = "震原",
  [":lvshi__zhenyuan"] = "蓄势技，其他角色的出牌阶段结束时，你可令除其外的角色依次选择是否使用一张中央区内没有的花色的牌并令其翻面，以此法使用的牌计入重置此技能需弃置的牌数。",
  ["#lvshi__zhenyuan-throw"] = "震原：请使用一张中央区内没有的花色的牌",
  
  ["$lvshi__zhenyuan1"] = "持盈守虚履忠节，略寇司敌继勋业！",
  ["$lvshi__zhenyuan2"] = "万军挥斥慑敌胆，一骑绝尘惧惊帆！",
}

local DIY = require "packages/diy_utility/diy_utility"
local ls = require "packages/lvshi/utility"

zhenyuan:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

zhenyuan:addEffect(fk.EventPhaseEnd, {
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(zhenyuan.name) and target.phase == Player.Play and ls.countSuits(DIY.getCenterCards(player.room)) < 4
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --local players = table.reverse(room:getAlivePlayers())
    local players = room:getOtherPlayers(target)
    for _, p in ipairs(players) do
      local suits = {"heart","diamond","spade","club"}
      local center_suits = {}
      for _, id in ipairs(DIY.getCenterCards(player.room)) do
        if Fk:getCardById(id).suit ~= Card.NoSuit then
          table.insertIfNeed(center_suits, Fk:getCardById(id):getSuitString())
        end
      end
      local to_throw = table.filter(suits, function(id) return not table.contains(center_suits, id) end)
      if #to_throw > 0 then
        local use = room:askToUseRealCard(p, {
          skill_name = zhenyuan.name,
          pattern = ".|.|" .. table.concat(to_throw, ","),
          prompt = "#lvshi__zhenyuan-throw",
          cancelable = true,
        })
        if use then
          DIY.changeReadyProgress(player, zhenyuan.name, 1, zhenyuan.name)
          target:turnOver() 
        end
      end
    end
  end,
})

return zhenyuan